﻿NewsEdit = {
    init: function () {
        $('input, select, textarea').live('keydown', function (e) {
            if (e.keyCode == 13) {
                var focusable = $('input,button,iframe,select,textarea').filter(':enabled');
                focusable.eq(focusable.index(this) + 1).focus();
                return false;
            }
        });
        $(".txtPrice").keypress(function (evt) {
            var theEvent = evt || window.event;
            var key = theEvent.keyCode || theEvent.which;

            key = String.fromCharCode(key);
            var regex = /[0-9]/;
            if (!regex.test(key)) {
                theEvent.returnValue = false;
                if (theEvent.preventDefault) theEvent.preventDefault();
            }
            else {
                if ($(this).val() != "") {
                    if (parseFloat($(this).val()) == 0) {
                        theEvent.returnValue = false;
                        if (theEvent.preventDefault) theEvent.preventDefault();
                    }
                }
            }
        });
        $(".txtPrice").bind('copy paste', function (e) {
            e.preventDefault();
        });
        $(".disable-item").attr("readonly", "readonly");
        $(".btn-browse").click(function () {
            NewsEdit.BrowseServer('file-path');
        });
    },

    BrowseServer: function (control) {
        // You can use the "CKFinder" class to render CKFinder in a page:
        var finder = new CKFinder();
        finder.basePath = '/ckfinder/'; // The path for the installation of CKFinder (default = "/ckfinder/").
        finder.selectActionData = control
        finder.selectActionFunction = function (fileUrl, data) {
            var control = data['selectActionData'];
            $('.' + control).val(fileUrl);
        }
        finder.resourceType = 'Images';
        finder.popup();

        // It can also be done in a single line, calling the "static"
        // popup( basePath, width, height, selectFunction ) function:
        // CKFinder.popup( '../', null, null, SetFileField ) ;
        //
        // The "popup" function can also accept an object as the only argument.
        // CKFinder.popup( { basePath : '../', selectActionFunction : SetFileField } ) ;
    },
    DeleteConfirm: function () {
        return confirm("Bạn có muốn delete tin này không?");
    }
}

$(document).ready(function () {
    NewsEdit.init();
})